package com.learn.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.learn.entity.system.SysRestAuth;
import com.learn.repository.system.SysRestAuthRepository;
import com.learn.service.SysRestAuthService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 接口权限service实现
 *
 * @author yaoqihui
 * @version 2022/11/3
 * @see [相关类/方法]
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class SysRestAuthServiceImpl implements SysRestAuthService
{
	private final SysRestAuthRepository sysRestAuthRepository;

	/**
	 * 根据操作员ID查询接口权限列表
	 *
	 * @param operatorId 操作员ID
	 * @return 接口权限列表
	 */
	@Override
	public List<String> queryRestAuths (String operatorId)
	{
		List<String> restAuthList = new ArrayList<> ();

		// 查询接口权限列表
		List<SysRestAuth> sysRestAuthList = sysRestAuthRepository.queryRestAuthByOperatorId (operatorId);
		if (CollUtil.isEmpty (sysRestAuthList))
		{
			return restAuthList;
		}
		sysRestAuthList.forEach (
				sysRestAuth -> restAuthList.add (sysRestAuth.getRestUri () + ";" + sysRestAuth.getRestMethod ()));
		return restAuthList;
	}
}
